#!/usr/bin/env python

import sys
import optparse
from itertools import izip
sys.path.append('4_simularity')

from metrics import theor_probability_gt

def main():
    parser = optparse.OptionParser(
        usage = '%prog -g GENOMES_NUM',
    )
    parser.add_option(
        '-g',
        dest = 'genomes_num',
        type = 'int',
    )
    opts, args = parser.parse_args()
    if not opts.genomes_num:
        print >> sys.stderr, parser.usage
        sys.exit(1)
    genomes_num  = opts.genomes_num
    
    for line in sys.stdin:
        unknown_gene_id, known_gene_id, ints_str = line.strip().split('\t')

        ints = map(int, ints_str.split(','))        
        n1   = min(ints[0], ints[1])
        n2   = max(ints[0], ints[1])
        n12  = int(ints[2])
        
        p = theor_probability_gt(genomes_num, n1, n2, n12) 
        sys.stdout.write("%s\t%s\t%f\t%s\n" % (unknown_gene_id, known_gene_id, p, ints_str))


if __name__ == '__main__':
    import gc
    gc.disable()
    
    main()
